﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SharedGenomics.Domain
{
    /// <summary>
    /// Contains a description of a SNP - the label assigned to it in the input file, its chromosome index and its position within the chromosome
    /// </summary>
    public class SnpDescriptor
    {
        #region Private Members

        private int chromosome;

        #endregion

        #region Constructors

        /// <summary>
        /// Creates a new instance of this class
        /// </summary>
        /// <param name="id">The id assigned to this SNP</param>
        public SnpDescriptor(long id)
            : this(id, 0)
        {
        }

        /// <summary>
        /// Creates a new instance of this class
        /// </summary>
        /// <param name="id">The id assigned to this SNP</param>
        /// <param name="chromosomeIndex">The chromosome number this SNP occurs in</param>
        public SnpDescriptor(long id, int chromosomeIndex)
            : this(id, chromosomeIndex, 0)
        {
        }

        /// <summary>
        /// Creates a new instance of this class
        /// </summary>
        /// <param name="id">The id assigned to this SNP</param>
        /// <param name="chromosomeIndex">The chromosome number this SNP occurs in</param>
        /// <param name="position">The position of this SNP within the chromosome</param>
        public SnpDescriptor(long id, int chromosomeIndex, long position)
        {
            this.Id = id;
            this.Chromosome = chromosomeIndex;
            this.Position = position;
        }

        #endregion

        #region Public Methods

        public override string ToString()
        {
            return String.Format("RS{0}", this.Id);
        }

        public override bool Equals(object obj)
        {
            SnpDescriptor comp = obj as SnpDescriptor;

            return (comp != null &&
                    this.Id == comp.Id &&
                    this.Chromosome == comp.Chromosome &&
                    this.Position == comp.Position);
        }

        public override int GetHashCode()
        {
            return this.Id.GetHashCode();
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the label assigned to this SNP
        /// </summary>
        public long Id { get; set; }
        
        /// <summary>
        /// Gets/sets the chromosome index this SNP occurs in
        /// </summary>
        public int Chromosome
        {
            get
            {
                return this.chromosome;
            }
            set
            {
                //chromosome cannot be greater than 26 for humans
                if (value < 0 || value > 26)
                    throw new ArgumentOutOfRangeException("Chromosome index must be in the range [0, 26]");

                this.chromosome = value;
            }
        }

        /// <summary>
        /// Gets/sets the position of this SNP within the chromosome
        /// </summary>
        public long Position { get; set; }

        public string MinorAllele { get; set; }

        #endregion
    }
}
